﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Util.Domains;
using Util.Domains.Auditing;

namespace IterationLife.Educations.Models {
    /// <summary>
    /// 教材
    /// </summary>
    [Description( "教材" )]
    public partial class TextBook : AggregateRoot<TextBook>,IDelete,IAudited {
        /// <summary>
        /// 初始化教材
        /// </summary>
        public TextBook() : this( Guid.Empty ) {
        }

        /// <summary>
        /// 初始化教材
        /// </summary>
        /// <param name="id">教材标识</param>
        public TextBook( Guid id ) : base( id ) {
            Syllabuses = new List<Syllabus>();
        }

        /// <summary>
        /// 科目编号
        /// </summary>
        public Guid? SubjectId { get; set; }
        /// <summary>
        /// 教材版本名称
        /// </summary>
        [StringLength( 20, ErrorMessage = "教材版本名称输入过长，不能超过20位" )]
        public string TextbookEditionName { get; set; }
        /// <summary>
        /// 教材版本编号
        /// </summary>
        public Guid? TextbookEditionId { get; set; }
        /// <summary>
        /// 名称
        /// </summary>
        [Required(ErrorMessage = "名称不能为空")]
        [StringLength( 100, ErrorMessage = "名称输入过长，不能超过100位" )]
        public string Name { get; set; }
        /// <summary>
        /// 年级
        /// </summary>
        [Required(ErrorMessage = "年级不能为空")]
        public int Grade { get; set; }
        /// <summary>
        /// 学期
        /// </summary>
        [Required(ErrorMessage = "学期不能为空")]
        public Guid Semester { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreationTime { get; set; }
        /// <summary>
        /// 创建人
        /// </summary>
        public Guid? CreatorId { get; set; }
        /// <summary>
        /// 最后修改时间
        /// </summary>
        public DateTime? LastModificationTime { get; set; }
        /// <summary>
        /// 最后修改人
        /// </summary>
        public Guid? LastModifierId { get; set; }
        /// <summary>
        /// 是否删除
        /// </summary>
        [Required(ErrorMessage = "是否删除不能为空")]
        public bool IsDeleted { get; set; }
        
        /// <summary>
        /// 课程大纲列表
        /// </summary>
        public virtual ICollection<Syllabus> Syllabuses { get; set; }
        
        /// <summary>
        /// 科目
        /// </summary>
        public virtual Subject Subject { get; set; }
        
        /// <summary>
        /// 教材版本
        /// </summary>
        public virtual TextbookEdition TextbookEdition { get; set; }
        
        /// <summary>
        /// 添加描述
        /// </summary>
        protected override void AddDescriptions() {
            AddDescription( "教材编号", Id );
            AddDescription( "科目编号", SubjectId );
            AddDescription( "教材版本名称", TextbookEditionName );
            AddDescription( "教材版本编号", TextbookEditionId );
            AddDescription( "名称", Name );
            AddDescription( "年级", Grade );
            AddDescription( "学期", Semester );
            AddDescription( "创建时间", CreationTime );
            AddDescription( "创建人", CreatorId );
            AddDescription( "最后修改时间", LastModificationTime );
            AddDescription( "最后修改人", LastModifierId );
        }
        
        /// <summary>
        /// 添加变更列表
        /// </summary>
        protected override void AddChanges( TextBook newEntity ) {
            AddChange( "Id", "教材编号", Id, newEntity.Id );            
            AddChange( "SubjectId", "科目编号", SubjectId, newEntity.SubjectId );
            AddChange( "TextbookEditionName", "教材版本名称", TextbookEditionName, newEntity.TextbookEditionName );
            AddChange( "TextbookEditionId", "教材版本编号", TextbookEditionId, newEntity.TextbookEditionId );
            AddChange( "Name", "名称", Name, newEntity.Name );
            AddChange( "Grade", "年级", Grade, newEntity.Grade );
            AddChange( "Semester", "学期", Semester, newEntity.Semester );
            AddChange( "CreationTime", "创建时间", CreationTime, newEntity.CreationTime );
            AddChange( "CreatorId", "创建人", CreatorId, newEntity.CreatorId );
            AddChange( "LastModificationTime", "最后修改时间", LastModificationTime, newEntity.LastModificationTime );
            AddChange( "LastModifierId", "最后修改人", LastModifierId, newEntity.LastModifierId );
        }
    }
}